﻿using SRB.Tg.Model;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.DatabaseServices;

namespace SRB.Tg.Cad
{
    public class Substructure
    {
        public void DrawingPile(ref DataRow row, ref double selectScale)
        {
            SelectInfoForm frm = new SelectInfoForm("pile");
            frm.ShowDialog();
            if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                PileParameter para = ModelOper.GetPilePara(frm.para.Id,out row);
                // 钢筋明细
                string selectString = string.Format("SELECT * FROM t_reinforcement_summary where part_type='{0}' and parent_id='{1}' and status=0  order by no asc", 2, frm.para.Id);
                System.Data.DataTable dt1 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);

                // 材料明细
                selectString = string.Format("SELECT * FROM t_material_summary where part_type='{0}' and parent_id='{1}' and calculate_type='{2}' and status=0 ", 2, frm.para.Id, 1);
                System.Data.DataTable dt2 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);
              
                int OverAllScale = frm.para.Scale;
                selectScale = OverAllScale;
                Pile P1 = new Pile(para);
                Database db = HostApplicationServices.WorkingDatabase;
                P1.DrawingPile(db, OverAllScale, dt1, dt2);
            }      
        }
        public void DrawingPileCap(ref DataRow row, ref double selectScale)
        {
            SelectInfoForm frm = new SelectInfoForm("pileCap");
            frm.ShowDialog();
            if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                PileCapParameter para = ModelOper.GetPileCapPara(frm.para.Id, out row);
                // 钢筋明细
                string selectString = string.Format("SELECT * FROM t_reinforcement_summary where part_type='{0}' and parent_id='{1}' and status=0  order by no asc", 1, frm.para.Id);
                System.Data.DataTable dt1 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);

                // 材料明细
                selectString = string.Format("SELECT * FROM t_material_summary where part_type='{0}' and parent_id='{1}' and calculate_type='{2}' and status=0 ", 1, frm.para.Id, 1);
                System.Data.DataTable dt2 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);
                int OverAllScale = frm.para.Scale;
                selectScale = OverAllScale;
                PileCap A = new PileCap(para);

                Database db = HostApplicationServices.WorkingDatabase;
                A.DrawingPileCap(db, OverAllScale, dt1, dt2);
            }
        }
        public void DrawingPlinth(ref DataRow row, ref double selectScale)
        {
            SelectInfoForm frm = new SelectInfoForm("Plinth");
            frm.ShowDialog();
            if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                PlinthParameter para = ModelOper.GetPlinthPara(frm.para.Id, out row);
                // 钢筋明细
                string selectString = string.Format("SELECT * FROM t_reinforcement_summary where part_type='{0}' and parent_id='{1}' and status=0  order by no asc", 3, frm.para.Id);
                System.Data.DataTable dt1 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);

                // 材料明细
                selectString = string.Format("SELECT * FROM t_material_summary where part_type='{0}' and parent_id='{1}' and calculate_type='{2}' and status=0  ", 3, frm.para.Id, 1);
                System.Data.DataTable dt2 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);

                int OverAllScale = frm.para.Scale;
                selectScale = OverAllScale;
                Plinth P1 = new Plinth(para);
                Database db = HostApplicationServices.WorkingDatabase;
                P1.DrawingPlinth(db, OverAllScale, dt1, dt2);
            }
        }
        public void DrawingPile(DataRow row, double selectScale)
        {

            PileParameter para = ModelOper.GetPilePara(row["id"].ToString(), out row);
            // 钢筋明细
            string selectString = string.Format("SELECT * FROM t_reinforcement_summary where part_type='{0}' and parent_id='{1}' and status=0  order by no asc", 2, row["id"].ToString());
            System.Data.DataTable dt1 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);

            // 材料明细
            selectString = string.Format("SELECT * FROM t_material_summary where part_type='{0}' and parent_id='{1}' and calculate_type='{2}' and status=0 ", 2, row["id"].ToString(), 1);
            System.Data.DataTable dt2 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);

            int OverAllScale = (int)selectScale;

            Pile P1 = new Pile(para);
            Database db = HostApplicationServices.WorkingDatabase;
            P1.DrawingPile(db, OverAllScale, dt1, dt2);

        }
        public void DrawingPileCap(DataRow row, double selectScale)
        {

            PileCapParameter para = ModelOper.GetPileCapPara(row["id"].ToString(), out row);
            // 钢筋明细
            string selectString = string.Format("SELECT * FROM t_reinforcement_summary where part_type='{0}' and parent_id='{1}' and status=0  order by no asc", 1, row["id"].ToString());
            System.Data.DataTable dt1 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);

            // 材料明细
            selectString = string.Format("SELECT * FROM t_material_summary where part_type='{0}' and parent_id='{1}' and calculate_type='{2}' and status=0 ", 1, row["id"].ToString(), 1);
            System.Data.DataTable dt2 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);
            int OverAllScale = (int)selectScale;
            //selectScale = OverAllScale;
            PileCap A = new PileCap(para);

            Database db = HostApplicationServices.WorkingDatabase;
            A.DrawingPileCap(db, OverAllScale, dt1, dt2);

        }

        public void DrawingPlinth(DataRow row, double selectScale)
        {

            PlinthParameter para = ModelOper.GetPlinthPara(row["id"].ToString(), out row);
            // 钢筋明细
            string selectString = string.Format("SELECT * FROM t_reinforcement_summary where part_type='{0}' and parent_id='{1}' and status=0  order by no asc", 3, row["id"].ToString());
            System.Data.DataTable dt1 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);
            // 材料明细
            selectString = string.Format("SELECT * FROM t_material_summary where part_type='{0}' and parent_id='{1}' and calculate_type='{2}' and status=0  ", 3, row["id"].ToString(), 1);
            System.Data.DataTable dt2 = MySqlHelper.ExecuteDataTable(selectString, System.Data.CommandType.Text);

            int OverAllScale = (int)selectScale;

            Plinth P1 = new Plinth(para);
            Database db = HostApplicationServices.WorkingDatabase;
            P1.DrawingPlinth(db, OverAllScale, dt1, dt2);

        }

    }

    public enum SubstructureType
    {      
        Pile, //桩基
        PileCap,//承台
        Plinth, //垫石
    }
}
